import request from '@/config/axios'

/**
 * 产品分类
 */
export interface CategoryVO {
  /**
   * 分类编号
   */
  id?: number | string
  /**
   * 父分类编号
   */
  parentId?: number | string
  /**
   * 分类名称
   */
  name: string
  /**
   * 移动端分类图
   */
  picUrl: string
  /**
   * 分类排序
   */
  sort: number
  /**
   * 开启状态
   */
  status: number
}

// 创建产品分类
export const createCategory = (data: CategoryVO) => {
  return request.post({ url: '/product/category/create', data })
}

// 更新产品分类
export const updateCategory = (data: CategoryVO) => {
  return request.put({ url: '/product/category/update', data })
}

// 删除产品分类
export const deleteCategory = (id: number | string) => {
  return request.delete({ url: `/product/category/delete?id=${id}` })
}

// 获得产品分类
export const getCategory = (id: number | string) => {
  return request.get({ url: `/product/category/get?id=${id}` })
}

// 获得产品分类列表
export const getCategoryList = (params: PageParam) => {
  return request.get({ url: '/product/category/list', params })
}

// 获得产品分类分页
export const getCategoryPage = (params: PageParam) => {
  return request.get({ url: '/product/category/page', params })
}

// 获得产品分类列表
export const getCategorySimpleList = (shopId: number | string = '') => {
  if (shopId) {
    return request.get({ url: `/product/category/list-simple?shopId=` + shopId })
  }
  return request.get({ url: `/product/category/list-simple` })
}
